const detect = require('detect-port').default || require('detect-port');
const { exec } = require('child_process');

const DEFAULT_PORT = 3000;

detect(DEFAULT_PORT).then(_port => {
  if (DEFAULT_PORT === _port) {
    exec('npm run react-start', { stdio: 'inherit', shell: true });
  } else {
    console.log(`Port ${DEFAULT_PORT} is occupied, using port ${_port} instead.`);
    exec(`set PORT=${_port}&& npm run react-start`, { stdio: 'inherit', shell: true });
  }
});
